//
//  ViewController.swift
//  DevFormView
//
//  Created by dev on 15/9/16.
//  Copyright (c) 2015年 devilved. All rights reserved.
//

import UIKit

class ViewController: UIViewController,DevFormFieldDelegate {

    @IBOutlet var formTableView: UIDevFormTableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initFormTableView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func initFormTableView() {
        var section:DevFormSection = DevFormSection()
        //section.backgroundColor = UIColor.orangeColor()
        section.height = 40
        section.labels = [
            ["text":"文本1", "color": UIColor.redColor()],
            ["text":"文本2", "color": UIColor.blueColor()]
        ]
        
        for var i=0; i<10; i++ {
            let field:DevFormTextRadioField = DevFormTextRadioField(name:"name", label:"姓名\(i)")
            field.defaultValue = "姓名\(i)"
            field.delegate = self
            field.returnKeyType = UIReturnKeyType.Next
            if i == 9 {
                field.returnKeyType = UIReturnKeyType.Go
            }
            section.fields.append(field)
            
        }
        
        self.formTableView.sections.append(section)
        
        section = DevFormSection()
        section.height = 40
        section.labels = [
            ["text":"文本1", "color": UIColor.redColor()],
            ["text":"文本2", "color": UIColor.blueColor()]
        ]
        
        for var i=10; i<20; i++ {
            let field:DevFormSwitchField = DevFormSwitchField(name:"name\(i)", label:"姓名\(i)")
            field.defaultValue = true
            field.delegate = self
            section.fields.append(field)
            
        }
        
        self.formTableView.sections.append(section)
        
        self.formTableView.reloadData()
    }
    
    func formField(onFocus formField: DevFormField, formTableView: UIDevFormTableView!) {
        print(formTableView.getFormValues())
    }
    
    func formField(onValueChange formField: DevFormField, formTableView: UIDevFormTableView!, newValue: AnyObject!, oldValue: AnyObject?) {
        
    }

}

